# include <stdio.h>
# include <string.h>
# include "Header.h"

int compareLength(char *DirName,char *filePath){ 
	int i = 0;
	int l = stringLength(DirName);
	while(i < l) {
		if( *(DirName + i) == *(filePath + i))
			i++;     	
		else {

			if(*(filePath + i - 1) == '/')
				i--;
			break;
		}
	}
	if(*(filePath + i - 1) == '/' && i == l)
		i--;	
	if( *(filePath + i) == '/' || *(filePath + i) == '\0') {
		return i;		
	}
	else
		return 0;
} 

int deleteDir(char *DirName, struct VFS *header) { 
	int i, l, val;
	int ret = 0;
	for(i = 0; i < MAX_FD_SIZE; i++) {
		if(header -> freeList[i]) {
			val = compareLength(DirName, header -> fd[i].filePath);
			if(val == stringLength(header -> fd[i].filePath)) {
				header -> freeList[i] = 0;				
				//header->fd[i].fileName = '\0';
				//header->fd[i].filePath = '\0';
				//header->fd[i].fileType = '\0';
				for (l = 0; l < 50; l++) {
					header -> fd[i].fileName[l] = '\0';
				}
				for (l = 0; l < 5; l++) {
					header -> fd[i].fileType[l] = '\0';
				}
				for (l = 0; l < 100; l++) {
					header -> fd[i].filePath[l] = '\0';
				}					
				header->fd[i].size = 0;
				for (l = 0; l < 1024; l++) {
					header -> bl[i].data[l] = '\0';
				}
				ret = 1;		
			}
		}
	}
	return ret;
}
